function convertToStarsArray(stars) {
  var array = [];
  if (stars) {
    var num = stars.toString().substring(0, 1); 
    for (var i = 1; i <= 5; i++) {
      if (i <= num) {
        array.push(1);
      } else {
        array.push(0);
      }
    }
  }
  return array;
}

function convertToCastString(casts) {
  var castsjoin = "";
  for (var idx in casts) {
    castsjoin = castsjoin + casts[idx].name + " / ";
  }

  return castsjoin.substring(0, castsjoin.length - 2);
}

function convertToCastInfos(casts) {
  var castsArray = [];
  for (var idx in casts) {
    var cast = {
      img: casts[idx].avatars ? casts[idx].avatars.large : "",
      name: casts[idx].name
    };
    castsArray.push(cast);
  }
  return castsArray;
}

/**
 * url : url
 * data : 参数
 * method : get，post
 * callback : 回掉函数
 */
function http(url, data, method, callback) {
  wx.request({
    url: url,
    data: data,
    header: { 'Content-Type': 'json' },
    method: method,
    success: function (res) {
      callback(res.data);
    },
    fail: function () {

    },
    complete: function () {

    }
  })
}


module.exports = {
  http: http,
  convertToStarsArray: convertToStarsArray,
  convertToCastString: convertToCastString,
  convertToCastInfos: convertToCastInfos
}